import java.io.File;
import java.util.Scanner;
import java.io.FileNotFoundException;
import java.util.NoSuchElementException;

/**
 * 
 * List containing Opponent items, along with method to read them in from a file.
 *
 */
public class OpponentList extends BaphiList {
	
	/**
	 * List containing Opponent items, along with a method to read them in from a file.
	 * @param fileName
	 * @throws FileNotFoundException
	 * @throws NoSuchElementException
	 */
	public OpponentList(String fileName) throws FileNotFoundException, NoSuchElementException
	{
		readOpponentsFromFile(fileName);
	}
	
	/**
	 * @return Opponent
	 */
	public Opponent get(int idx)
	{
		return (Opponent) super.get(idx);
	}

	/**
	 * Reads Opponents from the specified file path and populates the OpponentList
	 * @param fileName
	 * @throws FileNotFoundException
	 * @throws NoSuchElementException
	 */
	private void readOpponentsFromFile(String fileName) throws FileNotFoundException, NoSuchElementException
	{
		File file = new File(fileName);
		Scanner scan;
		String name;
		int attack;
		int defense;

		scan = new Scanner(file);
		scan.useDelimiter(",|\n");
		
		while(scan.hasNext())
		{	
			name = scan.next();
			attack = scan.nextInt();
			defense = scan.nextInt();
			
			this.add(new Opponent(name, attack, defense));
		}
		
		scan.close();
	}
}
